<style scoped>
    .g-header {
        background-color: #fff;
        width: 100%;
        position: fixed;
        left: 0;
        bottom: 0;
        z-index: 3;
        _zoom: 1;
    }
    .m-nav {
        background-color: #f1f1f1;
        border-bottom: 1px solid #d5d5d5;
        -webkit-box-shadow: 0 1px 3px 0 rgba(160, 160, 160, 0.2);
        box-shadow: 0 1px 3px 0 rgba(160, 160, 160, 0.2);
    }
    .g-wrap {
        margin: 0 auto;
        width: 100%;
        position: relative;
    }
    .m-nav-list, .m-lead-list, .m-goods-list {
        width: calc(100% - 0.2rem);
        padding: 0 0.1rem;
        display: -webkit-box;
    }
    .m-nav-list li, .m-lead-list li, .m-goods-list li {
        position: relative;
        text-align: center;
        box-flex: 1;
        -webkit-box-flex: 1;
        width: 1px;
    }
    .m-nav-list a {
        display: -webkit-flex;
        width: 100%;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        color: #7a7e83;
    }
    .m-nav-list .selected a i,.m-nav-list .selected a span {
        color: #ef3737;
    }
    .m-nav-list a i {
        display: inline-block;
        font-size: 0.24rem;
        line-height: 0.24rem;
        margin-top: 4px;
        text-align: center;
        padding: 0;
    }
    .ifont {
        margin: 0 3px;
        font-family: "ifont" !important;
        font-size: 16px;
        font-style: normal;
        -webkit-font-smoothing: antialiased;
        -webkit-text-stroke-width: 0.2px;
        -moz-osx-font-smoothing: grayscale;
    }

    .m-nav-list a span, .m-lead-list a span {
        display: inline-block;
        width: 100%;
        text-align: center;
        font-size: 0.13rem;
    }
    .m-simpleHeader {
        position: fixed;
        z-index: 2;
        left: 0;
        right: 0;
        height: 0.38rem;
        line-height: 0.38rem;
        border: 1px solid #D4D4D4;
        background: rgba(240, 240, 240, .8);
        top: 0;
        border-width: 0 0 1px;
        -webkit-box-shadow: 0 1px 3px 0px rgba(160, 160, 160, 0.2);
        -moz-box-shadow: 0 1px 3px 0px rgba(160, 160, 160, 0.2);
        box-shadow: 0 1px 3px 0px rgba(160, 160, 160, 0.2);
        text-align: center;
    }
    .m-simpleHeader-back {
        position: absolute;
        left: 0;
        padding: 0 0.15rem;
        overflow: hidden;
    }
    .m-simpleHeader h1 {
        font-size: 0.16rem;
        color: #222;
    }
    .ico-back {
        display: inline-block;
        width: 0.11rem;
        height: 0.11rem;
        border-style: solid;
        border-width: 2px 0 0 2px;
        color: #8a8a8a;
        -moz-transform: rotate(-45deg);
        -ms-transform: rotate(-45deg);
        -o-transform: rotate(-45deg);
        transform: rotate(-45deg);
        -webkit-transform: rotate(-45deg);
    }
    .visibility {
        visibility: hidden;
    }
</style>
<template>
    <!-- 导航栏 -->
    <div class="g-header">
        <div class="m-nav">
            <div class="g-wrap">
                <ul class="m-nav-list">
                    <li :class="[this.$route.matched[0].handler.path==item.path?'selected':'']" v-for="(key,item) in ifontData">
                        <a @click="navClick(key)">
                            <i class="ifont" v-html="item.icon" v-if="this.$route.matched[0].handler.path==item.path"></i>
                            <i class="ifont" v-html="item.iconCur" v-else></i>
                            <span>{{item.name}}</span>
                            <b v-if="item.name==='购物车'" :class="['w-miniCart-count', { visibility: cartNum==0}]" data-fn="cartnum">{{cartNum}}</b>
                        </a>
                    </li>
                </ul>
            </div>
        </div>
    </div>
</template>
<script>
    import Cart from '../module/cart'
    export default{
        props:['numprops'],
        data(){
            return{
                cartNum: 0,
                msg:'hello vue',
                ifontData: [{
                    name:"首页",
                    icon:"&#xe662;",
                    iconCur:"&#xe663;",
                    path:"/home"
                },{
                    name:"商品",
                    icon:"&#xe665;",
                    iconCur:"&#xe667;",
                    path:"/list"
                },{
                    name:"晒单",
                    icon:"&#xe666;",
                    iconCur:"&#xe668;",
                    path:"/shareOrder"
                },{
                    name:"购物车",
                    icon:"&#xe664;",
                    iconCur:"&#xe66a;",
                    path:"/cart"
                },{
                    name:"我",
                    icon:"&#xe661;",
                    iconCur:"&#xe669;",
                    path:"/user"
                }]
            }
        },

        watch:{
            numprops(val){

                this.cartNum=val;

            }
        },

        ready () {
            console.warn(Cart.cart)
            console.log('nav & cartnum ' + Cart.getCartNum() + ' & ' + this.cartnum)
            this.cartNum = Cart.getCartNum()
        },
        methods: {
            updateCartnum(){

                this.cartnum = Cart.getCartNum()

            },
            navClick (index) {

                switch(index)
                {
                    case 0:
                        return this.$router.go('/home');
                    case 1:
                        return this.$router.go('/list')
                    case 2:
                        return this.$router.go('/shareOrder')
                    case 3:
                        return this.$router.go('/cart')
                    case 4:
                        return this.$router.go('/user')
                    default:
                        return this.$router.go('/home');
                }

            }
        }
    }
</script>
